package com.yidu.best.systemManagement.roleManagement.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.best.systemManagement.roleManagement.domain.Role;
import com.yidu.best.systemManagement.roleManagement.domain.RoleVo;
import com.yidu.best.systemManagement.roleManagement.service.RoleService;



@Controller
@RequestMapping("/roleController/")
public class RoleController {
	@Autowired
	private RoleService roleService;
	
	@RequestMapping(value="toRoleList",method=RequestMethod.GET)
	public String toRole(){
		return "sys/role/roleList";
		
	}
	@RequestMapping(value="role",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> findRole(RoleVo roleVo){
		Map<String, Object> map = new HashMap<String, Object>();
		map=roleService.findRole(roleVo);
		return map;
	}
	@RequestMapping(value="role",method=RequestMethod.POST)
	@ResponseBody
	public boolean addRole(Role role){
		int addRole = roleService.addRole(role);
		if(addRole==1){
			return true; 
		}
		return false;
	}
	@RequestMapping(value="role/{roleIds}",method=RequestMethod.DELETE)
	@ResponseBody
	public boolean deleteRole(@PathVariable("roleIds")String roleIds){
		int deleteRole=0;
		String[] roleId = roleIds.split(",");
		for(int i=0;i<roleId.length;i++){
			deleteRole = roleService.deleteRole(roleId[i]);
		}
		if(deleteRole==1){
			return true;
		}
		return false;
		
	}
	
	@RequestMapping(value="role",method=RequestMethod.PUT)
	@ResponseBody
	public boolean updateRole(Role role){
		int updateRole = roleService.updateRole(role);
		if(updateRole==1){
			return true;
		}
		return false;
		
	}
}
